<template>
  <el-dialog
    title="上传备案"
    :close-on-click-modal="false"
    @close="closeHandle"
    v-loading="uploading"
    :element-loading-text="this.tip"
    :visible.sync="visible">
    <el-upload
      drag
      :action="url"
      ref="upload"
      :before-upload="beforeUploadHandle"
      :on-success="successHandle"
      :on-error="errorHandle"
      accept=".pdf,.PDF"
      :show-file-list="false"
      :data="{seqno:this.seqno}"
      :limit="1"
      :file-list="fileList"
      style="text-align: center;">

      <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
      <div class="el-upload__tip" slot="tip">请上传pdf格式文件！</div>
    </el-upload>


  </el-dialog>



</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        url: '',
        seqno: 0,
        successNum: 0,
        failDetail: [],
        fileList: [],
        uploading: false,
        tip: '正在上传'
      }
    },
    methods: {
      init (id) {
        this.fileList = []
        this.seqno = id
        this.url = this.$http.adornUrl(`/bdc/bdcproxyinfo/upload?token=${this.$cookie.get('token')}`)
        this.visible = true
      },
      // 上传之前
      beforeUploadHandle (file) {
        this.uploading = true
      },
      errorHandle(err){
        this.uploading = false
        this.$message.error("上传失败")
      },
      // 上传成功
      successHandle (response, file) {
        this.uploading = false
        if (response && response.code === 0) {
            this.$message({
              message: "上传备案成功",
              type: 'success',
              duration: 1500,
              onClose: () => {
                this.visible = false
                this.$emit('refreshDataList')
              }
            });           
        } else {
          this.$message.error(response.msg)
          this.$refs.upload.clearFiles()
        }
      },
      // 弹窗关闭时
      closeHandle () {

        this.$emit('refreshDataList')
      }
    }
  }
</script>
